package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.Article;
import com.ssm.sfzy.entity.ArticleType;
import com.ssm.sfzy.mapper.ArticleMapper;
import com.ssm.sfzy.mapper.ArticleTypeMapper;
import com.ssm.sfzy.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author yang "每天都要学习呀"
 * @Date 2024 03 30 11 26
 **/
@Service
public class ArticleTypeServiceImpl implements ArticleTypeService {
    @Autowired
    private ArticleTypeMapper articleTypeMapper;

    @Override
    public void add(ArticleType entity) {
        articleTypeMapper.insert(entity);
    }

    @Override
    public void edit(ArticleType entity) {
        articleTypeMapper.update(entity);

    }

    @Override
    public void remove(Integer id) {
        articleTypeMapper.delete(id);

    }

    @Override
    public void removeBatch(Integer[] ids) {
        articleTypeMapper.deleteBatch(ids);

    }

    @Override
    public List<ArticleType> find(ArticleType entity) {
        return articleTypeMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ArticleType entity) {
        //
        PageHelper.startPage(pageNum,pageSize);
        List<ArticleType> list = articleTypeMapper.select(entity);
        //
        PageInfo<ArticleType> pageInfo = new PageInfo<>(list);
        // 整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public ArticleType findById(Integer id) {
        ArticleType articleType = articleTypeMapper.selectById(id);
        return articleType;
    }
}
